package com.sky.wsp.lucene.service;

import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Component;

import java.util.concurrent.Future;

/**
 * @desccription 在此输入描述
 * @auth wangshaopeng@talkweb.com.cn
 * @date 2022/5/7
 */
@Component
public class AsyncUserService {

    @Async
    public Future<String> execTaskA() throws InterruptedException {
        long star = System.currentTimeMillis();
        System.out.println("TaskA开始：" + star);
        Thread.sleep(2000);
        long end = System.currentTimeMillis();
        System.out.println("TaskA结束，耗时毫秒数：" + (end - star));
        return new AsyncResult<>("TaskA结束");
    }

    @Async
    public Future<String> execTaskB() throws InterruptedException {
        long star = System.currentTimeMillis();
        System.out.println("TaskB开始：" + star);
        Thread.sleep(3000);
        long end = System.currentTimeMillis();
        System.out.println("TaskB结束，耗时毫秒数：" + (end - star));
        return new AsyncResult<>("TaskB结束");
    }

    @Async
    public Future<String> execTaskC() throws InterruptedException {
        long star = System.currentTimeMillis();
        System.out.println("TaskC开始：" + star);
        Thread.sleep(4000);
        long end = System.currentTimeMillis();
        System.out.println("TaskC结束，耗时毫秒数：" + (end - star));
        return new AsyncResult<>("TaskC结束");
    }
}
